package cn.zyk.config;

import cn.zyk.condition.MysqlDataSourceCondition;
import cn.zyk.condition.OracleDataSourceCondition;
import cn.zyk.service.DatabaseDriver;
import cn.zyk.service.DatabaseTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Scope;
import org.springframework.web.client.RestTemplate;

/**
 * @Author eHlw
 * @Date 2024/9/19 15:25
 * @description:
 */
@Configuration
public class AppConfig {

    @Autowired
    private ResourcePathConfig resourcePathConfig;

    @Bean
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

    @Bean

    public DatabaseTemplate jdbcTemplate() throws Exception {
        DatabaseTemplate databaseTemplate = new DatabaseTemplate(resourcePathConfig);
        return databaseTemplate;

    }


    @Bean
    @Conditional(OracleDataSourceCondition.class)
    public DatabaseTemplate getOracleDatabaseDriver() throws Exception {
        return new DatabaseTemplate(resourcePathConfig);
    }

    @Bean
    @Conditional(MysqlDataSourceCondition.class)
    public DatabaseTemplate getMysqlDatabaseDriver() throws Exception {
        return new DatabaseTemplate(resourcePathConfig);
    }


}
